package com.ptmall.app.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.LogBean;
import com.ptmall.app.bean.OrderBean;
import com.ptmall.app.ui.activity.OrderDetilActivity;
import com.ptmall.app.view.NoScrollListView;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */

public class OrderNoticeAdapter extends BaseAdapter {

    private Context mContext;
    private List<LogBean> mDataList;
    private LayoutInflater mLayoutInflater;
    private OrderGoodAdapter mOrderGoodAdapter;


    ClickInterface clickInterface;


    public void setClickInterface(ClickInterface clickInterface) {
        this.clickInterface = clickInterface;
    }


    public OrderNoticeAdapter(Context context, List<LogBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<LogBean> list) {
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mDataList == null) {
            return 0;
        }
        return mDataList.size();
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_messagegood,  parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        LogBean bean = mDataList.get(position);
        mOrderGoodAdapter = new OrderGoodAdapter(mContext, bean.product_list);
        viewHolder.goodlist.setAdapter(mOrderGoodAdapter);
        viewHolder.goodlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Intent intent = new Intent(mContext, OrderDetilActivity.class);
                intent.putExtra("id", bean.orderId);
                mContext.startActivity(intent);
            }
        });
        switch (bean.status){
            case "1":
                viewHolder.title.setText("开始配送");
                break;
            case "2":
                viewHolder.title.setText("已送达");
                break;
        }
        viewHolder.orderno.setText("订单编号："+bean.order_number);
        viewHolder.address.setText("配送地址："+bean.address);
        return convertView;
    }

    class ViewHolder {

        NoScrollListView goodlist;
        TextView address, orderno,title;


        ViewHolder(View view) {
            goodlist = (NoScrollListView) view.findViewById(R.id.goodlist);
            address = (TextView) view.findViewById(R.id.address);
            orderno = (TextView) view.findViewById(R.id.orderno);
            title = (TextView) view.findViewById(R.id.title);
        }
    }


    public interface ClickInterface {
        void btn1Click(String id, int position, String status);

        void btn2Click(String id, int position, String status);
    }


}
